﻿using CUREBusinessLogicLayer.Harmful;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;

namespace CURE.Handler
{
    /// <summary>
    /// ExpFileHandler 的摘要说明
    /// </summary>
    public class ExpFileHandler : IHttpHandler
    {
        private LedgerBll ledgerbll = new LedgerBll();

        public void ProcessRequest(HttpContext context)
        {
            string lid = context.Request.QueryString["ledgerid"];

            DataSet ds = GetUploadExp(lid);
            if (ds != null && ds.Tables.Count > 0)
            {
                context.Response.Write(HtmlStr(ds));
            }
        }

        private DataSet GetUploadExp(string lid)
        {
            return ledgerbll.GetUploadExp(lid);
        }

        private string HtmlStr(DataSet ds)
        {
            string html = "";
            html += ("<table  width=\"100%\" bordercolor=\"#a0c6e5\" style=\"border-collapse:collapse;\" ><tr><td style=\"text-align: center;border: solid 1px #a0c6e5; height: 20px;\">文件名</td><td style=\"text-align: center;border: solid 1px #a0c6e5; height: 20px;\">附件</td><td style=\"text-align: center;border: solid 1px #a0c6e5; height: 20px;\">操作</td></tr>");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                int index = ds.Tables[0].Rows[i]["PATH"].ToString().LastIndexOf("/");
                string filename = ds.Tables[0].Rows[i]["PATH"].ToString().Substring(index + 1, ds.Tables[0].Rows[i]["PATH"].ToString().Length - index - 1);
                html += ("<tr><td style=\"text-align: center;border: solid 1px #a0c6e5; height: 20px;\">"+filename+"</td><td style=\"text-align: center;border: solid 1px #a0c6e5; height: 20px;\"><a target=\"blank\" href=" + ds.Tables[0].Rows[i]["PATH"].ToString() + "><img src=" + ds.Tables[0].Rows[i]["PATH"].ToString() + " style=\"width:50px;height:50px;\" /></a></td><td style=\"text-align: center;border: solid 1px #a0c6e5; height: 20px;\"><a target=\"ajaxTodo\" href=\"javascript:void(0);\" title=\"确定要删除吗?\" class=\"btnDel\" onclick=\"return DeleteFile('" + ds.Tables[0].Rows[i]["ID"].ToString() + "','" + ds.Tables[0].Rows[i]["PATH"].ToString() + "')\" >删除</a></td></tr>");
            }
            html += ("</table>");
           // html = "<span style=\"color:red;\">cccc</span>";
            return html;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}